//
// Created by sanfen on 2021/3/9.
//
#include <GL/gl.h>
#include <GL/glu.h>
#include <QOpenGLWidget>
#include "Monitor64x32GL.h"


Monitor64x32GL::Monitor64x32GL(QWidget *parent) :QOpenGLWidget(parent){

}

//清屏
void Monitor64x32GL::initializeGL() {
    glClearColor(0.0,0.0,0.0,0.0);
}

void Monitor64x32GL::resizeGL(int width, int height) {
    gluPerspective(45.0,(GLfloat)width/(GLfloat)height,0.1,100);
    glLoadIdentity();
}

//绘制像素点
void Monitor64x32GL::paint_pixel(int row, int col, float color) {
    float screen_row_width=1.0/64.0*2;
    float screen_col_width=1.0/32.0*2;
    glColor3f(color/255.0,color/255.0,color/255.0);  //函数颜色
    glBegin(GL_QUADS);  //开始绘制
    glVertex2f(screen_row_width*col,-screen_col_width*row);  //二维坐标绘制点
    glVertex2f(screen_row_width*col,-screen_col_width*(row+1.0));
    glVertex2f(screen_row_width*(col+1.0),-screen_col_width*(row+1.0));
    glVertex2f(screen_row_width*(col+1.0),-screen_col_width*row);
    glEnd();
}

void Monitor64x32GL::paint_cell(int row, int col, unsigned char color) {
    int pixel_row=row*PIXEL_SIZE_SC;
    int pixel_col=col*PIXEL_SIZE_SC;
    int drow,dcol;
    //观察像素绘制是否正常
//    for(drow=0;drow<PIXEL_SIZE_SC;drow++){
//        for(dcol=0;dcol<PIXEL_SIZE_SC;dcol++){
//            paint_pixel(pixel_row+drow,pixel_col+dcol.color);
//        }
//    }
}


Monitor64x32GL::~Monitor64x32GL()  {

}